<template>
  <div class="add_address">
    <van-address-edit
      :area-list="areaList"
      show-search-result
      :search-result="searchResult"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @change-detail="onChangeDetail"
    />
  </div>
</template>

<script>
import { areaList } from '@vant/area-data'
import { Toast } from 'vant'

export default {
  data() {
    return {
      areaList,
      searchResult: [],
      addresData: []
    }
  },
  created() {
    this.addresData = JSON.parse(localStorage.getItem("addres") || "[]")
  },
  methods: {
    onSave(content) {
      this.addresData.push(content)
      localStorage.setItem('addres', JSON.stringify(this.addresData))
      Toast('成功保存...')
      console.log(content)
      this.$router.push('/my/my_address')
    },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: '黄龙万科中心',
            address: '杭州市西湖区'
          }
        ]
      } else {
        this.searchResult = []
      }
    }
  }
}
</script>

<style>
.add_address{
  background: white;
}

</style>